﻿using Jet.Payment.Cielo.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Web;
using System.Xml;
using System.Xml.Serialization;

namespace Jet.Payment.Cielo
{
    public static class CieloService
    {
        public static Response.TransactionShortResponse GetUrl(Request.TransactionRequest transaction)
        {
            if (!transaction.PaymentType.Validate())
                throw new Exception("Request invalid");
            if (transaction.EC == null)
                transaction.EC = new ECData() { Key = Config.CredentialKey, Number = Config.CredentialNumber };
            return Utils.Request<Response.TransactionShortResponse, Request.TransactionRequest>(transaction);
        }

        public static Response.TransactionResponse GetStatus(Request.SelectRequest selectRequest)
        {
            if(string.IsNullOrEmpty( selectRequest.TransactionId))
                throw new Exception("TransactionId is required");
            if (selectRequest.EC == null)
                selectRequest.EC = new ECData() { Key = Config.CredentialKey, Number = Config.CredentialNumber };

            return Utils.Request<Response.TransactionResponse, Request.SelectRequest>(selectRequest);
        }
    }
}
